<%@ page import="com.teichmann.core.targets.online.*, com.teichmann.bo.*" contentType="text/html;charset=UTF-8" language="java"
	isELIgnored="false"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/functions" prefix="fn" %>  
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<link rel="shortcut icon" href="img/favicon.ico">
<META NAME="Description" CONTENT="Buscador automóveis RS Revendas carros">
<link type="text/css" rel="stylesheet" href="css/screen.css">

<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<meta name="google-site-verification" content="qhrbhHgJcPMh-iibZKUL3xSRVeOPC7xXrXkXkY5wQ9I" />
<title>AcheMeuCarro.com.br - Histórico de buscas</title>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js" type="text/javascript"></script>

</head>
<c:set var="count" value="0" />
<body>
<jsp:include page="menu.jsp"/>

<%
History h  = History.getInstance();
request.setAttribute("history", h);
%>

<c:choose>
<c:when test="${fn:length(history.query) != 0}" >
<div class="wrap" align="center">
  	<table width="250">
		<tr>
			<th> Modelo </th>
			<th> Itens</th>
			<th></th>
		</tr>
		<c:forEach var="car" items="${history.query}" varStatus="status">
			<c:choose>
				<c:when test="${count%2 == 0}">
					<tr  class="even">
				</c:when>
				<c:otherwise>
					<tr class="doven">
				</c:otherwise>
			</c:choose>
					<td>${car.key}</td>
					<td>${car.value}</td>
					<td align="right">
					   <a id="link" name="link" >
						<img name="view" alt="Refazer pesquisa" title="Refazer pesquisa" src="img/view.gif" > 
					   </a> 
					</td>
				</tr>
			<c:set var="count" value="${count+1}" />
		</c:forEach>
	</table>
  </div>
</c:when>
<c:otherwise>
  <br></br>
  <div class="wrap" align="center">
	Não existe histórico no momento.
  </div>
</c:otherwise>
</c:choose>

	

<input type="hidden" id="jsessionid" name="jsessionid" value="<c:out value="${pageContext.session.id}"/>"></input>
</body>
<script>
$(document).ready(function(){
    $("#link").live('click',function () {

      	count = $("a[name=link]").index(this);
    	det = $("tr > td");
		var modelo = $("tr:eq("+ (count+1) +") > td:eq(0)").text();
  	
    	var det2 = $("img[name=view]");
    	det2.eq(count).attr("src","img/loading3.gif"); 


    	var data = { 'origem[]' : ['<%=AutoCarro.class.getSimpleName()%>','<%=AutoCentro.class.getSimpleName()%>','<%=SulRevendas.class.getSimpleName()%>','<%=CarroNaSerra.class.getSimpleName()%>','<%=MeuCarroNovo.class.getSimpleName()%>'], 'modelo' : [],'jsessionid':[]};
	       
	        data['modelo[]'] = modelo ;
	        data['jsessionid'] = $('#jsessionid').val();
	        
	        jQuery.ajax({
	             type: "POST",
	             url: "search?id="+ $('#jsessionid').val(),
	             dataType:"html",
	             data: data,
	             success:function(response){      
			           location.href ='listResults.jsp?id='+data['jsessionid'];   
	             }
   			 });         
	})
})

</script>

</html>